package per.jdz.demo.listener;

import com.mybatisflex.annotation.InsertListener;
import com.mybatisflex.annotation.UpdateListener;
import per.jdz.demo.domain.entity.OriginHouseData;
import per.jdz.demo.utils.Md5Utils;

/**
 * @author Jdz
 * @date 2025/2/6
 */
public class UpsertListener implements InsertListener, UpdateListener {
    @Override
    public void onInsert(Object o) {
        hashValue((OriginHouseData)o);
    }

    @Override
    public void onUpdate(Object o) {
        hashValue((OriginHouseData)o);
    }
    public void hashValue(OriginHouseData houseData) {
        String city = houseData.getCity();
        String projectName = houseData.getProjectName();
        String buildingNumber = houseData.getBuildingNumber();
        String roomNumber = houseData.getRoomNumber();
        String floor = houseData.getFloor();
        String projectAddress = houseData.getProjectAddress();
        String t = city + projectName + buildingNumber + roomNumber + floor;
        String t2 = city + projectName + projectAddress;
        houseData.setHashValue(Md5Utils.hash(t));
        houseData.setRenameHashValue(Md5Utils.hash(t2));
    }
}
